
package org.ros.android.view;

import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.topic.Publisher;

import random_num_10.My_random_num_value;

public class MyRos_sendTextPublish extends AbstractNodeMain {
    private String topic_name;
    Publisher<std_msgs.String> publisher;
    public MyRos_sendTextPublish() {
        this.topic_name = "/multinav/work_mode_ctrl";
    }

    public MyRos_sendTextPublish(String topic) {
        this.topic_name = topic;
    }

    public void sendStringData(String data) {
        //this.callable = callable;
        if(publisher!=null) {
            //L.e("-----------MyRos_sendTextPublishxxxxxxxxx-----sendStringData---------data="+data);
            std_msgs.String str = (std_msgs.String) publisher.newMessage();
            str.setData(data);
            publisher.publish(str);
        }
    }


    public GraphName getDefaultNodeName() {
        return GraphName.of("/multinav/work_mode_ctrl"+ My_random_num_value.random_num);
    }

    public void onStart(ConnectedNode connectedNode) {
        publisher = connectedNode.newPublisher(this.topic_name, "std_msgs/String");
        /*
        connectedNode.executeCancellableLoop(new CancellableLoop() {
            private int sequenceNumber;

            protected void setup() {
                this.sequenceNumber = 0;
            }

            protected void loop() throws InterruptedException {
                std_msgs.String str = (std_msgs.String)publisher.newMessage();
                str.setData("mark_result_request");
                //L.e("---------------");
                //publisher.publish(str);
                ++this.sequenceNumber;
                Thread.sleep(5000L);
            }
        });
        */
    }
}
